import axios from 'axios'
import { CONFIG } from './config'

// 获取店铺列表（用户端）
export function getUserShopList(options) {
  let url = 'shop/public/shop/shopList'
  let data = {
    loStr: options.loStr || null,
    laStr: options.laStr || null,
    shopCode: options.shopCode || '',
    merchantId: options.merchantId || null,
    shopName: options.shopName || '',
    shopType: options.shopType || 1
  }
  return axios.post(url, {
    header: CONFIG.HEADER,
    playload: data
  }).then((res) => {
    // console.log(res)
    return Promise.resolve(res.data)
  }).catch((err) => {
    console.log(err)
  })
}

// 查找店铺橱窗商品
export function findShowCaseRecommendList(options) {
  const url = 'shop/public/commodity/findShowCaseRecommendList'
  const data = {
    shopCode: options.shopCode
  }
  return axios.post(url, {
    header: CONFIG.HEADER,
    playload: data
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    console.log(err)
  })
}

// 查询广告机
export function findAdMachine(options) {
  const url = 'shop/public/ad/findAdMachine'
  const data = {
    adMachineCode: options.adMachineCode,
    status: options.status || 'open',
    isOnline: options.isOnline || 1,
    connect: options.connect || 1,
    isOpen: options.isOpen || 'Y',
    templeteId: options.templeteId || null,
    province: options.province || null,
    city: options.city || null,
    area: options.area || null,
    adLocation: options.adLocation || null,
    allowAdType: options.allowAdType || null,
    lon: options.lon,
    lat: options.lat
  }
  return axios.post(url, data).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    console.log(err)
  })
}

// 登录获取验证码
export function getValidateCode(phoneNum) {
  let url = `gateway/public/userInfo/getValidateCode/${phoneNum}`
  let data = {}
  return axios.post(url, {
    header: CONFIG.HEADER,
    playload: data
  }).then((res) => {
    // console.log(res)
    return Promise.resolve(res.data)
  }).catch((err) => {
    console.log(err)
  })
}

// 新的绑定手机号到微信
export function shopBindWithCreate(options) {
  let url = 'gateway/public/userInfo/shopBindWithCreate'
  let data = options
  return axios.post(url, {
    header: CONFIG.HEADER,
    playload: data
  }).then((res) => {
    // console.log(res)
    return Promise.resolve(res.data)
  }).catch((err) => {
    console.log(err)
  })
}

// 获取我的资料
export function getByAccessToken() {
  let url = 'gateway/public/userInfo/getByAccessToken'
  let data = {
    accessToken: localStorage.uuToken
  }
  return axios.post(url, {
    header: CONFIG.HEADER,
    // header: {
    //   accessToken: localStorage.uuToken,
    //   appId: 71,
    //   platform: 'WX'
    // },
    playload: data
  }).then((res) => {
    // console.log(res)
    return Promise.resolve(res.data)
  }).catch((err) => {
    console.log(err)
  })
}